package com.vol.controller.sys;

import com.vol.entity.Result;
import com.vol.entity.SysDepartment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;


@RestController
@RequestMapping("api/sys_user")
public class User2Controller {
    @PostMapping("upload")
    public Result upload(@RequestParam("fileInput") MultipartFile file) throws IOException {
        System.out.println("1234");
        if (file.isEmpty()) {
            return Result.build(null, null, "上传文件为空！", false);
        }

        String UPLOAD_DIR = "D:\\";
        byte[] bytes = file.getBytes();
        Path path = Paths.get(UPLOAD_DIR + file.getOriginalFilename());
        File uploadDir = new File(UPLOAD_DIR);
        if (!uploadDir.exists()) {
            uploadDir.mkdirs();
        }
        Files.write(path, bytes);
        return Result.ok(null, null, "文件上传成功！");

    }
}
